package com.heima.wemedia.controller.v1;

import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.wemedia.service.WmChannelService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
@RequiredArgsConstructor
public class WmChannelController {

    private final WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult findAll() {
        return wmChannelService.findAll();
    }


    /**
     * 频道名称模糊分页查询-API
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listChannelByPage(@RequestBody ChannelDto dto){
       return wmChannelService.listChannelByPage(dto);
    }

    /**
     * 删除频道-根据频道id
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannelById(@PathVariable Integer id){
        return wmChannelService.deleteChannelById(id);
    }


    /**
     * 保存频道
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody AdChannel adChannel){
        return wmChannelService.saveChannel(adChannel);
    }

    /**
     * 更新频道
     * @param adChannel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel){
        return wmChannelService.updateChannel(adChannel);
    }
}
